import Vue from 'vue';
import {
    getQuestionList, createQuestionOrUpdate,
    deleteQuestion,
    getPaperList,
    creatPaperOrUpdate,
    getExamSendList,
    createExamSendOrUpdate,
    deleteExamSend,
    getRecordList,
    delRecord,
    createOrUpdate,
    searchPaperTopic,
    getExamMonitorList,
    createMonitorOrUpdate,
    delMonitorList,
    getUserFromId,
    MarkingPapers,
    deletePaper,
    selectVideUrl,
    examPerson,
    getExamTryRoll
} from "@/api/exam"

const state = {
    questionList: null,
    paperList: null,
    examSendList: null,
    recordList: null,
    examMonitorList: null,
    activeName: '',//当前题型
    edit: {
        type: 0,//默认为普通编辑，1位阅读编辑
        name: ''
    },
    readIndex: -1,//阅读题编辑时,选择题目下标
    readList: [],//阅读类型
    exam: {
        dan: {
            title: '',
            score: '2',
            pattern: 0,
            paper_name: '',
            show_type: '单选题',
            type: '单选题',
            answer: '',
            A: '',
            B: '',
            C: '',
            D: '',
            E: '',
            F: '',
        },
        duo: {
            title: '',
            score: '2',
            pattern: 0,
            paper_name: '',
            show_type: '多选题',
            answer: [],
            type: '多选题',
            A: '',
            B: '',
            C: '',
            D: '',
            E: '',
            F: '',
        },
        pan: {
            title: '',
            score: '2',
            pattern: 0,
            paper_name: '',
            show_type: '判断题',
            answer: '',
            type: '判断题',
            A: '',
            B: ''
        },
        tian: {
            title: '',
            score: '2',
            pattern: 0,
            paper_name: '',
            show_type: '填空题',
            answer: [],
            type: '填空题'
        },
        jieda: {
            title: '',
            score: '2',
            pattern: 0,
            paper_name: '',
            show_type: '简答题',
            answer: '',
            type: "简答题"
        },
        saoma: {
            title: '',
            score: '2',
            pattern: 0,
            paper_name: '',
            show_type: '扫码题',
            answer: '',
            type: "扫码题"
        },
        read: {
            title: '',
            score: '2',
            pattern: 0,
            paper_name: '',
            show_type: '阅读题',
            answer: '',
            type: "阅读题"
        },
    }
};
const getters = {
    questionList: (status) => status.questionList,
    readList: (status) => status.readList,
    activeName: (status) => status.activeName,
    paperList: (status) => status.paperList,
    examSendList: (status) => status.examSendList,
    examMonitorList: (status) => status.examMonitorList,
}
const mutations = {
    setReadIndex(state, data) {
        state.readIndex = data;
    },
    setExamMonitorList(state, data) {
        state.examMonitorList = data;
    },
    setRecordList(state, data) {
        state.recordList = data;
    },
    setExamSendList(state, data) {
        state.examSendList = data;
    },
    setActionName(state, data) {
        state.activeName = data;
    },
    setPaperList(state, data) {
        state.paperList = data;
    },
    setDan(state, data) {
        state.exam.dan.title = data['title'],
            state.exam.dan.score = data['score'],
            state.exam.dan.pattern = data['pattern'],
            state.exam.dan.paper_name = data['paper_name'],
            state.exam.dan.show_type = data['show_type'],
            state.exam.dan.type = data['type'],
            state.exam.dan.answer = data['answer'],
            state.exam.dan.A = data['A'],
            state.exam.dan.B = data['B'],
            state.exam.dan.C = data['C'],
            state.exam.dan.D = data['D'],
            state.exam.dan.E = data['E'],
            state.exam.dan.F = data['F']
    },
    setDuoAnsw(state) {
        state.exam.duo.answer = [];
    },
    setDuo(state, data) {
        state.exam.duo.title = data['title'],
            state.exam.duo.score = data['score'],
            state.exam.duo.pattern = data['pattern'],
            state.exam.duo.paper_name = data['paper_name'],
            state.exam.duo.show_type = data['show_type'],
            state.exam.duo.type = data['type'],
            state.exam.duo.answer = data['answer'],
            state.exam.duo.A = data['A'],
            state.exam.duo.B = data['B'],
            state.exam.duo.C = data['C'],
            state.exam.duo.D = data['D'],
            state.exam.duo.E = data['E'],
            state.exam.duo.F = data['F']
    },
    setPan(state, data) {
        state.exam.pan.title = data['title'],
            state.exam.pan.score = data['score'],
            state.exam.pan.pattern = data['pattern'],
            state.exam.pan.paper_name = data['paper_name'],
            state.exam.pan.show_type = data['show_type'],
            state.exam.pan.type = data['type'],
            state.exam.pan.answer = data['answer'],
            state.exam.pan.A = data['A'],
            state.exam.pan.B = data['B']
    },
    setTian(state, data) {
        state.exam.tian.title = data['title'],
            state.exam.tian.score = data['score'],
            state.exam.tian.pattern = data['pattern'],
            state.exam.tian.paper_name = data['paper_name'],
            state.exam.tian.show_type = data['show_type'],
            state.exam.tian.type = data['type'],
            state.exam.tian.answer = data['answer']
    },
    setJieDa(state, data) {
        state.exam.jieda.title = data['title'],
            state.exam.jieda.score = data['score'],
            state.exam.jieda.pattern = data['pattern'],
            state.exam.jieda.paper_name = data['paper_name'],
            state.exam.jieda.show_type = data['show_type'],
            state.exam.jieda.type = data['type'],
            state.exam.jieda.answer = data['answer']
    },
    setSaoMa(state, data) {
        state.exam.saoma.title = data['title'],
            state.exam.saoma.score = data['score'],
            state.exam.saoma.pattern = data['pattern'],
            state.exam.saoma.paper_name = data['paper_name'],
            state.exam.saoma.show_type = data['show_type'],
            state.exam.saoma.type = data['type'],
            state.exam.saoma.answer = data['answer']
    },
    setReadVlaue(state, data) {
        state.exam.read.title = data['title'],
            state.exam.read.score = data['score'],
            state.exam.read.pattern = data['pattern'],
            state.exam.read.paper_name = data['paper_name'],
            state.exam.read.show_type = data['show_type'],
            state.exam.read.type = data['type']
    },
    setQuestionList(state, data) {
        state.questionList = data;
    },
    setRead(state, data) {
        state.edit.type = data['type'];
        state.edit.name = data['name'];
    },
    setReadList(state, data) {
        if (state.readIndex != -1) {//修改
            Vue.set(state.readList, state.readIndex, data);
        } else {
            state.readList.push(data);
        }
    },
    setReadListValue(state, data) {
        state.readList = data;
    },
    delReadList(state, index) {
        state.readList.splice(index, 1);
    }
}
const actions = {
    async getQuestionList({commit}, param) {
        const {data} = await getQuestionList(param);
        commit("setQuestionList", data);
    },
    async getPaperList({commit}, param) {
        const {data} = await getPaperList(param);
        commit("setPaperList", data);
    },
    async getExamSendList({commit}, param) {
        const {data} = await getExamSendList(param);
        commit("setExamSendList", data);
    },
    async getRecordList({commit}, param) {
        const {data} = await getRecordList(param);
        commit("setRecordList", data);
    },
    async getExamMonitorList({commit}, param) {
        const {data} = await getExamMonitorList(param);
        commit("setExamMonitorList", data);
    },

    async createQuestionOrUpdate({commit}, param) {
        return await createQuestionOrUpdate(param);
    },
    async deleteQuestion({commit}, param) {
        return await deleteQuestion(param);
    },
    async creatPaperOrUpdate({commit}, param) {
        return await creatPaperOrUpdate(param);
    },
    async deletePaper({commit}, param) {
        return await deletePaper(param);
    },
    async createExamSendOrUpdate({commit}, param) {
        return await createExamSendOrUpdate(param);
    },
    async deleteExamSend({commit}, param) {
        return await deleteExamSend(param);
    },
    async delRecord({commit}, param) {
        return await delRecord(param);
    },
    async createOrUpdate({commit}, param) {
        return await createOrUpdate(param);
    },
    async searchPaperTopic({commit}, param) {
        return await searchPaperTopic(param);
    },
    async createMonitorOrUpdate({commit}, param) {
        return await createMonitorOrUpdate(param);
    },
    async delMonitorList({commit}, param) {
        return await delMonitorList(param);
    },
    async getUserFromId({commit}, param) {
        return await getUserFromId(param);
    },
    async MarkingPapers({commit}, param) {
        return await MarkingPapers(param);
    },
    async selectVideUrl({commit}, param) {
        return await selectVideUrl(param);
    },
    async examPerson({commit}, param) {
        return await examPerson(param);
    },

    async getExamTryRoll({commit}, param) {
        return await getExamTryRoll(param);
    },

}

export default {state, getters, mutations, actions};
